package my.StudentAdministratie;

import java.util.List;

import javax.swing.table.AbstractTableModel;

public class XMLTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 1043610367760128061L;
	
	private static final String[] COLUMNS = new String[] { "Naam", "Studentnummer", "Woonplaats" };
	private List<Student> list;

	public XMLTableModel(List<Student> list) {
		this.list = list;
	}

	@Override
	public String getColumnName(int index) {
		if(index < 0 || index >= COLUMNS.length)
			return "";

		return COLUMNS[index];
	}

	public int getRowCount() {
		return list.size();
	}

	public int getColumnCount() {
		return COLUMNS.length;
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		//Get student
		Student student = list.get(rowIndex);
		if(student == null)
			return "null";
		
		//switch column, note: if you add columns make sure to add them here as well
		switch(columnIndex) {
		case 0:
			return student.naam;
			
		case 1:
			return student.studentnummer;
			
		case 2:
			return student.woonplaats;
			
		default:
			throw new IndexOutOfBoundsException("Requested an unknown column");
		}
	}


}